package com.itheima.tlias.controller;

import com.itheima.tlias.comment.MyComment;
import com.itheima.tlias.dto.AddClazzDto;
import com.itheima.tlias.dto.CheckClazzDto;
import com.itheima.tlias.dto.UpdateClazzDto;
import com.itheima.tlias.entity.Clazz;
import com.itheima.tlias.service.ClazzService;
import com.itheima.tlias.utils.Constant;
import com.itheima.tlias.vo.ClazzListVo;
import com.itheima.tlias.vo.PageBean;
import com.itheima.tlias.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;
    @MyComment(desc = "班级条件分页查询")
    @GetMapping
    public Result<PageBean<ClazzListVo>> clazzPage(CheckClazzDto dto) {
        PageBean<ClazzListVo> clazzPage = clazzService.clazzPage(dto);
        return Result.success(clazzPage);
    }
    @MyComment(desc = "班级新增")
    @PostMapping
    public Result<Void> addClazz(@RequestBody AddClazzDto dto) {
        clazzService.addClazz(dto);
        return Result.success();
    }
    @MyComment(desc = "班级删除")
    @DeleteMapping("/{id}")
    public Result<Void> deleteClazz(@PathVariable(Constant.ID) Integer id) {
        clazzService.deleteClazz(id);
        return Result.success();
    }
    @MyComment(desc = "班级修改功能 数据回显")
    @GetMapping("{id}")
    public Result<Clazz> getById(@PathVariable(Constant.ID) Integer id) {
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);

    }
    @MyComment(desc = "班级修改")
    @PutMapping
    public Result<Void> updateClazz(@RequestBody UpdateClazzDto dto) {
        clazzService.updateClazz(dto);
        return Result.success();
    }
    @MyComment(desc = "学生管理接口，班级回显")
    @GetMapping("/list")
    public Result<List<Clazz>> students(){
        List<Clazz> students = clazzService.students();
        return Result.success(students);
    }
}
